home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / GLX / DBglxwidget / GlxDraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  54.1 KB  |  1,845 lines

  1. static char rcsid[]=
  2.  "$Header: /d1/carlson/pda/glxwidget/RCS/GlxDraw.c,v 4.8 93/06/11 16:06:27 carlson Exp $";
  3. /*
  4.  *    These files are for informational purposes and can demonstrate how
  5.  *   to write your own mixed-mode GL-based widgets.  However SGI does not
  6.  *   guarantee that this source code absolutely matches the GLxDraw
  7.  *   widget that is shipped as part of the system.
  8.  *
  9.  *   New Version by Chris Carlson and Ed Millard
  10.  *   supports switching between single and double buffering
  11.  */
  12.  
  13. /***********************************************************
  14. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  15. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  16.  
  17.                         All Rights Reserved
  18.  
  19. Permission to use, copy, modify, and distribute this software and its 
  20. documentation for any purpose and without fee is hereby granted, 
  21. provided that the above copyright notice appear in all copies and that
  22. both that copyright notice and this permission notice appear in 
  23. supporting documentation, and that the names of Digital or MIT not be
  24. used in advertising or publicity pertaining to distribution of the
  25. software without specific, written prior permission.  
  26.  
  27. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  28. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  29. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  30. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  31. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  32. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  33. SOFTWARE.
  34.  
  35. ******************************************************************/
  36.  
  37.  
  38. /*------------------------------------------------------------------------
  39.  *  III   N   N   CCC   L      U   U  DDDD   EEEEE   SSS
  40.  *   I    NN  N  C   C  L      U   U  D   D  E      S   S
  41.  *   I    NN  N  C      L      U   U  D   D  E      S
  42.  *   I    N N N  C      L      U   U  D   D  EEE     SSS
  43.  *   I    N  NN  C      L      U   U  D   D  E          S
  44.  *   I    N  NN  C   C  L      U   U  D   D  E      S   S
  45.  *  III   N   N   CCC   LLLLL   UUU   DDDD   EEEEE   SSS
  46.  *------------------------------------------------------------------------*/
  47.  
  48. #ifdef DEBUG
  49. #include <stdio.h>
  50. #endif
  51.  
  52. #include <X11/IntrinsicP.h>
  53. #include <X11/StringDefs.h>
  54.  
  55. #include <X11/Xatom.h>
  56. #include <X11/Xutil.h>
  57. #include <gl/get.h>
  58.  
  59. #ifdef __GLX_MOTIF
  60. #include <Xm/XmP.h>
  61.  
  62. #ifdef SVR4
  63. #include <Xm/PrimitiveP.h>
  64. #endif
  65.  
  66. #include "GlxMDrawP.h"
  67.  
  68. #else            /* not __GLX_MOTIF */
  69.  
  70. #include "GlxDrawP.h"
  71.  
  72. #endif            /* __GLX_MOTIF */
  73.  
  74. /*------------------------------------------------------------------------
  75.  * DDDD   EEEEE  FFFFF   III   N   N  EEEEE   SSS
  76.  * D   D  E      F        I    NN  N  E      S   S
  77.  * D   D  E      F        I    NN  N  E      S
  78.  * D   D  EEE    FFF      I    N N N  EEE     SSS
  79.  * D   D  E      F        I    N  NN  E          S
  80.  * D   D  E      F        I    N  NN  E      S   S
  81.  * DDDD   EEEEE  F       III   N   N  EEEEE   SSS
  82.  *------------------------------------------------------------------------*/
  83.  
  84. #ifdef __GLX_MOTIF
  85. /* The MOTIF version differs only in the inclusion of the primitive
  86.  * widget class and in a vew variable and type name differences.
  87.  * Rather than put ifdefs all over the place, we just use a few defines
  88.  * to make it use motif types and names
  89.  */
  90. #define GlxDrawWidget        GlxMDrawWidget
  91. #define GlxDrawClassRec        GlxMDrawClassRec
  92. #define glxDrawClassRec        glxMDrawClassRec
  93. #define glxDrawWidgetClass    glxMDrawWidgetClass
  94. #define GlxDrawRec        GlxMDrawRec
  95. #endif /* __GLX_MOTIF */
  96.  
  97. #define MAX_CONFIG 128
  98.  
  99. /*----
  100.  * Explanation of DEBUG definitions:
  101.  *    bitmap    enables
  102.  *    ------    -------
  103.  *    defnd    Calls XSynchronize before doing 'Initialize'.
  104.  *    0x0002    Print colormap info
  105.  *    0x0004    Print window IDs
  106.  *    0x0008    Print visual info
  107.  *    0xFFFE    Will print info useful to all of the above
  108.  *----*/
  109.  
  110. /*------------------------------------------------------------------------
  111.  * M   M   AAA    CCC   RRRR    OOO    SSS
  112.  * MM MM  A   A  C   C  R   R  O   O  S   S
  113.  * MM MM  A   A  C      R   R  O   O  S
  114.  * M M M  AAAAA  C      RRRR   O   O   SSS
  115.  * M   M  A   A  C      R R    O   O      S
  116.  * M   M  A   A  C   C  R  R   O   O  S   S
  117.  * M   M  A   A   CCC   R   R   OOO    SSS
  118.  *------------------------------------------------------------------------*/
  119.  
  120. #define offset(field) XtOffset(GlxDrawWidget, glxDraw.field)
  121.  
  122. /*------------------------------------------------------------------------
  123.  * L       OOO    CCC    AAA   L       SSS
  124.  * L      O   O  C   C  A   A  L      S   S
  125.  * L      O   O  C      A   A  L      S
  126.  * L      O   O  C      AAAAA  L       SSS
  127.  * L      O   O  C      A   A  L          S
  128.  * L      O   O  C   C  A   A  L      S   S
  129.  * LLLLL   OOO    CCC   A   A  LLLLL   SSS
  130.  *------------------------------------------------------------------------*/
  131.  
  132. static char defaultTranslations[] =
  133.     "<KeyDown>:    glxInput() \n\
  134.      <KeyUp>:    glxInput() \n\
  135.      <BtnDown>: glxInput() \n\
  136.      <BtnUp>:   glxInput() \n\
  137.      <BtnMotion>: glxInput() ";
  138.  
  139. static void glxInput();
  140. static void auxwindow_destroyed();
  141.  
  142. static GLXconfig default_config[] = {{0,0,0}};
  143. static XtActionsRec actions[] = {
  144.     { "glxInput", glxInput },    /* key or mouse input */
  145. };
  146.  
  147. static XtResource resources[] = {
  148.   {GlxNglxConfig, GlxCGlxConfig, GlxRGlxConfig, sizeof(GLXconfig *),
  149.        offset(config),
  150.        XtRImmediate, (caddr_t) default_config},
  151.  
  152.   {GlxNginitCallback, GlxCCallback, XtRCallback, sizeof (XtCallbackList),
  153.        offset(ginit_callback), XtRImmediate, (caddr_t) NULL},
  154.  
  155.   {GlxNinputCallback, GlxCCallback, XtRCallback, sizeof (XtCallbackList),
  156.        offset(input_callback), XtRImmediate, (caddr_t) NULL},
  157.  
  158.   {GlxNresizeCallback, GlxCCallback, XtRCallback, sizeof (XtCallbackList),
  159.        offset(resize_callback), XtRImmediate, (caddr_t) NULL},
  160.  
  161.   {GlxNexposeCallback, GlxCCallback, XtRCallback, sizeof (XtCallbackList),
  162.        offset(expose_callback), XtRImmediate, (caddr_t) NULL},
  163.  
  164.   {GlxNvisual, GlxCVisual, GlxRVisualInfo, sizeof (XVisualInfo *),
  165.        offset(visualInfo), XtRImmediate, (caddr_t) NULL},
  166.  
  167.   {GlxNoverrideColormap, GlxCOverrideColormap, XtRBoolean, sizeof (Boolean),
  168.        offset(override_colormap), XtRImmediate, (caddr_t) TRUE},
  169.  
  170.   {GlxNuseOverlay, GlxCUseOverlay, XtRBoolean, sizeof (Boolean),
  171.        offset(overlay_info.exists), XtRImmediate, (caddr_t) FALSE},
  172.  
  173.   {GlxNoverlayWindow, GlxCWindow, XtRWindow, sizeof (Window),
  174.        offset(overlay_info.window), XtRImmediate, (caddr_t) 0},
  175.  
  176.   {GlxNoverlayColormap, GlxCColormap, XtRColormap, sizeof (Colormap),
  177.        offset(overlay_info.colormap), XtRImmediate, (caddr_t) 0},
  178.  
  179.   {GlxNoverlayDepth, GlxCDepth, XtRInt, sizeof (int),
  180.        offset(overlay_info.depth), XtRImmediate, (caddr_t) 0},
  181.  
  182.   {GlxNoverlayVisual, GlxCVisual, GlxRVisualInfo, sizeof (XVisualInfo *),
  183.        offset(overlay_info.visualInfo), XtRImmediate, (caddr_t) 0},
  184.  
  185.   {GlxNoverlayExposeCallback, GlxCCallback, XtRCallback,
  186.        sizeof (XtCallbackList),
  187.        offset(overlay_info.expose_callback), XtRImmediate, (caddr_t) NULL},
  188.  
  189.   {GlxNuseUnderlay, GlxCUseUnderlay, XtRBoolean, sizeof (Boolean),
  190.        offset(underlay_info.exists), XtRImmediate, (caddr_t) FALSE},
  191.  
  192.   {GlxNunderlayWindow, GlxCWindow, XtRWindow, sizeof (Window),
  193.        offset(underlay_info.window), XtRImmediate, (caddr_t) 0},
  194.  
  195.   {GlxNunderlayColormap, GlxCColormap, XtRColormap, sizeof (Colormap),
  196.        offset(underlay_info.colormap), XtRImmediate, (caddr_t) 0},
  197.  
  198.   {GlxNunderlayDepth, GlxCDepth, XtRInt, sizeof (int),
  199.        offset(underlay_info.depth), XtRImmediate, (caddr_t) 0},
  200.  
  201.   {GlxNunderlayVisual, GlxCVisual, GlxRVisualInfo, sizeof (XVisualInfo *),
  202.        offset(underlay_info.visualInfo), XtRImmediate, (caddr_t) 0},
  203.  
  204.   {GlxNunderlayExposeCallback, GlxCCallback, XtRCallback,
  205.        sizeof (XtCallbackList),
  206.        offset(underlay_info.expose_callback), XtRImmediate, (caddr_t) NULL},
  207.  
  208.   {GlxNusePopup, GlxCUsePopup, XtRBoolean, sizeof (Boolean),
  209.        offset(popup_info.exists), XtRImmediate, (caddr_t) FALSE},
  210.  
  211.   {GlxNpopupWindow, GlxCWindow, XtRWindow, sizeof (Window),
  212.        offset(popup_info.window), XtRImmediate, (caddr_t) 0},
  213.  
  214.   {GlxNpopupColormap, GlxCColormap, XtRColormap, sizeof (Colormap),
  215.        offset(popup_info.colormap), XtRImmediate, (caddr_t) 0},
  216.  
  217.   {GlxNpopupDepth, GlxCDepth, XtRInt, sizeof (int),
  218.        offset(popup_info.depth), XtRImmediate, (caddr_t) 0},
  219.  
  220.   {GlxNpopupVisual, GlxCVisual, GlxRVisualInfo, sizeof (XVisualInfo *),
  221.        offset(popup_info.visualInfo), XtRImmediate, (caddr_t) 0},
  222.  
  223.   {GlxNpopupExposeCallback, GlxCCallback, XtRCallback, sizeof (XtCallbackList),
  224.        offset(popup_info.expose_callback), XtRImmediate, (caddr_t) NULL},
  225.  
  226.   {GlxNmainWindow, GlxCWindow, XtRWindow, sizeof (Window),
  227.        offset (mainWindow), XtRImmediate, (caddr_t) 0},
  228.  
  229.   {GlxNprovideSingleBuffer, GlxCProvideSingleBuffer, XtRBoolean,
  230.        sizeof (Boolean),
  231.        offset(provide_Sbuffer), XtRImmediate, (caddr_t) NULL},
  232.  
  233.   {GlxNsingleBuffer, GlxCSingleBuffer, XtRBoolean, sizeof (Boolean),
  234.        offset(single_buffer), XtRImmediate, (caddr_t) NULL},
  235.  
  236.   {GlxNaltColormap, GlxCColormap, XtRColormap, sizeof (Colormap),
  237.        offset(alt_colormap), XtRImmediate, (caddr_t)0},
  238.  
  239. #ifdef __GLX_MOTIF
  240.   /* Primitive resources */
  241.   {XmNtraversalOn, XmCTraversalOn, XmRBoolean, sizeof (Boolean),
  242.        XtOffset (GlxDrawWidget, primitive.traversal_on), XmRImmediate,
  243.        (caddr_t) FALSE},
  244.   
  245.   {XmNhighlightOnEnter, XmCHighlightOnEnter, XmRBoolean, sizeof (Boolean),
  246.        XtOffset (GlxDrawWidget, primitive.highlight_on_enter), XmRImmediate,
  247.        (caddr_t) FALSE},
  248.   
  249.   {XmNshadowThickness, XmCShadowThickness, XmRHorizontalDimension,
  250.        sizeof (Dimension),
  251.        XtOffset (GlxDrawWidget, primitive.shadow_thickness), XmRImmediate,
  252.        (caddr_t) 0},
  253.   
  254.   {XmNhighlightThickness, XmCHighlightThickness, XmRHorizontalDimension,
  255.        sizeof (Dimension),
  256.        XtOffset (GlxDrawWidget, primitive.highlight_thickness), XmRImmediate,
  257.        (caddr_t) 0},
  258. #endif            /* __GLX_MOTIF */
  259.   
  260. #undef offset
  261. };
  262.  
  263. static void
  264.     ClassInitialize(),
  265.     Initialize(),
  266.     Realize(),
  267.     CreateWindow(),
  268.     Redraw(),
  269.     Resize(),
  270.     Destroy();
  271. static Boolean
  272.     SetValues();
  273.  
  274. /*------------------------------------------------------------------------
  275.  *  GGG   L       OOO   BBBB    AAA   L       SSS
  276.  * G   G  L      O   O  B   B  A   A  L      S   S
  277.  * G      L      O   O  B   B  A   A  L      S
  278.  * G      L      O   O  BBBB   AAAAA  L       SSS
  279.  * G GGG  L      O   O  B   B  A   A  L          S
  280.  * G   G  L      O   O  B   B  A   A  L      S   S
  281.  *  GGG   LLLLL   OOO   BBBB   A   A  LLLLL   SSS
  282.  *------------------------------------------------------------------------*/
  283.  
  284. GlxDrawClassRec glxDrawClassRec =
  285. {
  286.   { /* core fields */
  287. #ifdef __GLX_MOTIF
  288.     /* superclass        */    (WidgetClass) &xmPrimitiveClassRec,
  289.     /* class_name        */    "GlxMDraw",
  290. #else /* not __GLX_MOTIF */
  291.     /* superclass        */    (WidgetClass) &widgetClassRec,
  292.     /* class_name        */    "GlxDraw",
  293. #endif /* __GLX_MOTIF */
  294.     /* widget_size        */    sizeof(GlxDrawRec),
  295.     /* class_initialize        */    ClassInitialize,
  296.     /* class_part_initialize    */    NULL,
  297.     /* class_inited        */    FALSE,
  298.     /* initialize        */    Initialize,
  299.     /* initialize_hook        */    NULL,
  300.     /* realize            */    Realize,
  301.     /* actions            */    actions,
  302.     /* num_actions        */    XtNumber(actions),
  303.     /* resources        */    resources,
  304.     /* num_resources        */    XtNumber(resources),
  305.     /* xrm_class        */    NULLQUARK,
  306.     /* compress_motion        */    TRUE,
  307.     /* compress_exposure    */    TRUE,
  308.     /* compress_enterleave    */    TRUE,
  309.     /* visible_interest        */    TRUE,
  310.     /* destroy            */    Destroy,
  311.     /* resize            */    Resize,
  312.     /* expose            */    Redraw,
  313.     /* set_values        */    SetValues,
  314.     /* set_values_hook        */    NULL,
  315.     /* set_values_almost    */    XtInheritSetValuesAlmost,
  316.     /* get_values_hook        */    NULL,
  317.     /* accept_focus        */    NULL,
  318.     /* version            */    XtVersion,
  319.     /* callback_private        */    NULL,
  320.     /* tm_table            */    defaultTranslations,
  321.     /* query_geometry        */    XtInheritQueryGeometry,
  322.     /* display_accelerator    */    XtInheritDisplayAccelerator,
  323.     /* extension        */    NULL
  324.   },
  325. #ifdef __GLX_MOTIF /* primitive resources */
  326.   {
  327.     /* border_highlight        */    XmInheritBorderHighlight,
  328.     /* border_unhighlight    */    XmInheritBorderUnhighlight,
  329.     /* translations        */    XtInheritTranslations,
  330.     /* arm_and_activate        */    NULL,
  331.     /* get_resources        */    NULL,
  332.     /* num get_resources    */    0,
  333.     /* extension        */    NULL,                
  334.   }
  335. #endif /* __GLX_MOTIF */
  336. };
  337. WidgetClass glxDrawWidgetClass = (WidgetClass)&glxDrawClassRec;
  338.  
  339. /*------------------------------------------------------------------------
  340.  * error
  341.  *------------------------------------------------------------------------*/
  342.  
  343. static char *gl_errs[] = {
  344.     "No error", "No context", "No display", "No window", "No graphics",
  345.     "Not top", "No visual", "Buffer size too small", "Bad window",
  346. };
  347.  
  348. static void  error(w,string)
  349.   Widget w;
  350.   char *string;
  351. {
  352.     char buf[100];
  353. #ifdef __GLX_MOTIF
  354.     sprintf (buf, "GlxMDraw: %s\n", string);
  355. #else
  356.     sprintf (buf, "GlxDraw: %s\n", string);
  357. #endif
  358.     XtAppError(XtWidgetToApplicationContext(w), buf);
  359. }
  360.  
  361. /*------------------------------------------------------------------------
  362.  * warning
  363.  *------------------------------------------------------------------------*/
  364.  
  365. static void warning(w,string)
  366.   Widget w;
  367.   char *string;
  368. {
  369.     char buf[100];
  370. #ifdef __GLX_MOTIF
  371.     sprintf (buf, "GlxMDraw: %s\n", string);
  372. #else
  373.     sprintf (buf, "GlxDraw: %s\n", string);
  374. #endif
  375.     XtAppWarning(XtWidgetToApplicationContext(w), buf);
  376. }
  377.  
  378. /*------------------------------------------------------------------------
  379.  * Documentation
  380.  *    I thought it would be appropriate to document some of the more
  381.  *    confusing stuff here.  It's actually here to help me remember
  382.  *    what's going on.
  383.  *
  384.  *    ClassInitialize
  385.  *      [Called by: X]
  386.  *        Called when widgets of this class are to be initialized.
  387.  *
  388.  *    Initialize
  389.  *      [Called by: X]
  390.  *        Called to initialize the widget.
  391.  *        1.  Fills in default values for widget structure.
  392.  *        2.  Uses the resources to figure out visuals and
  393.  *            colormaps to be used.
  394.  *        3.  If both single and double buffered windows are
  395.  *            to exist, fill in all the same sort of stuff
  396.  *            for the second window.
  397.  *
  398.  *    SetValuesAux
  399.  *      [Called by:    SetAux]
  400.  *      [Calls:    XChangeWindowAttributes]
  401.  *        Used to set up common resources for overlay, underlay
  402.  *        and popup windows.  Calls XChangeWindowAttributes for
  403.  *        a change in colormaps.
  404.  *
  405.  *    SetNewWindow
  406.  *      [Called by:    SetValues]
  407.  *      [Calls:    XGetGeometry]
  408.  *      [        GLXwinset]
  409.  *      [        XResizeWindow]
  410.  *      [        XMapWindow]
  411.  *      [        ResizeAux]
  412.  *        Used to switch from single/double buffer window to
  413.  *        double/single buffer window.  Gets information about
  414.  *        the current window and sets the same info in the new
  415.  *        window.
  416.  *
  417.  *        Things that are maintained here:
  418.  *          mmode [with all matricies]    lsbackup
  419.  *          displaymode            lsrepeat
  420.  *          backface            lstyle
  421.  *          cmmode            pattern
  422.  *          color                scrmask
  423.  *          map                sm (shading model)
  424.  *          cursor            writemask
  425.  *          dcm (depthcue)        geometry
  426.  *          font
  427.  *    SetAux
  428.  *      [Called by:    SetValues]
  429.  *      [Calls:    SetValuesAux]
  430.  *        Used to cal SetValuesAux for each of the overlay,
  431.  *        underlay and popup planes.
  432.  *
  433.  *    SetValues
  434.  *      [Called by:    X]
  435.  *      [Calls:    SetAux]
  436.  *      [        XUnmapWindow]
  437.  *      [        SetNewWindow]
  438.  *        Called to change any resources.
  439.  *
  440.  *    RealizeAux
  441.  *      [Called by:    Realize]
  442.  *      [Calls:    XCreateWindow]
  443.  *      [        XMapWindow]
  444.  *      [        XSelectInput]
  445.  *      [        _XtRegisterWindow]
  446.  *        Used to setup and realize each of the overlay, underlay
  447.  *        and/or popup windows.
  448.  *
  449.  *    RealizeAuxDup
  450.  *      [Called by:    RealizeDup]
  451.  *      [Calls:    XCreateWindow]
  452.  *      [        XMapWindow]
  453.  *      [        XSelectInput]
  454.  *      [        _XtRegisterWindow]
  455.  *        Identical to RealizeAux except to be used to set up
  456.  *        these windows for the secondary window (single/double
  457.  *        buffered window).
  458.  *
  459.  *    RealizeCreateRGBColorMap
  460.  *      [Called by:    RealizeDup]
  461.  *      [        Realize]
  462.  *      [Calls:    XGetVisualInfo]
  463.  *      [        XCreateColormap]
  464.  *      [        DefaultColormap]
  465.  *      [        XStoreColors]
  466.  *      [        XGetRGBColormaps]
  467.  *        Currently not used.  Does something with setting up
  468.  *        colormap for PseudoColor visuals.
  469.  *
  470.  *    RealizeDup
  471.  *      [Called by:    Realize]
  472.  *      [Calls:    RealizeCreateRGBColorMap*]
  473.  *      [        XCreateColormap*]
  474.  *      [        XCreateWindow]
  475.  *      [        XSelectInput]
  476.  *      [        _XtRegisterWindow]
  477.  *      [        XSetWMColormapWindows]
  478.  *      [        RealizeAuxDup]
  479.  *      [        GLXlink]
  480.  *        Basically, this is a duplicate of Realize except it
  481.  *        sets up the second window.
  482.  *
  483.  *    Realize
  484.  *      [Called by:    X]
  485.  *      [Calls:    RealizeCreateRGBColorMap*]
  486.  *      [        XQueryColors*]
  487.  *      [        XtCreateWindow]
  488.  *      [        RealizeAux]
  489.  *      [        GLXlink]
  490.  *      [        RealizeDup]
  491.  *      [        GLXwinset]
  492.  *      [        XtAddEventHandler]
  493.  *      [        XtCallCallbackList]
  494.  *        Does all the functions required to actually bring the
  495.  *        window up.
  496.  *
  497.  *    Redraw
  498.  *      [Called by:    X]
  499.  *
  500.  *    ResizeCallback
  501.  *
  502.  *    ResizeAux
  503.  *
  504.  *    ResizeDup
  505.  *
  506.  *    Resize
  507.  *      [Called by:    X]
  508.  *
  509.  *    Destroy
  510.  *      [Called by:    X]
  511.  *
  512.  *    glxInput
  513.  *
  514.  *    auxwindow_destroyed
  515.  *
  516.  *    GlxCreateMDraw
  517.  *      [Called by:    User]
  518.  *
  519.  *  * = Commented out
  520.  *------------------------------------------------------------------------*/
  521.  
  522.  
  523. /*------------------------------------------------------------------------
  524.  * ClassInitialize
  525.  *------------------------------------------------------------------------*/
  526.  
  527. static void ClassInitialize()
  528. {
  529. }
  530.  
  531. /*------------------------------------------------------------------------
  532.  * InitializeDup
  533.  *    Called to create the second window when both single and double
  534.  *    buffered windows are wanted.
  535.  *------------------------------------------------------------------------*/
  536.  
  537. static void InitializeDup (new, secondary, config)
  538.   GlxDrawWidget new;
  539.   GlxDrawBuffer *secondary;
  540.   GLXconfig *config;
  541. {
  542.     GLXconfig        *newConfig, *tmpConfig;
  543.     GlxDrawWindowInfo    *curWindowInfo;
  544.     XVisualInfo        tmpl;
  545.     int            nret;
  546.  
  547.     /*----
  548.      * Make a duplicate GLwindow for switch to double
  549.      * buffering
  550.      *----*/
  551.  
  552.     newConfig = GLXgetconfig (XtDisplay (new),
  553.                   XScreenNumberOfScreen (XtScreen (new)),
  554.                   config);
  555.     if (!newConfig)
  556.     {
  557.     error (new, "Unable to get second visual");
  558.     return;
  559.     }
  560.         
  561.     secondary->config = newConfig;
  562.  
  563.     bzero (&secondary->info, sizeof (GlxDrawWindowInfo));
  564.     curWindowInfo = &secondary->info;
  565.     curWindowInfo->exists = True;
  566.     if (!new->glxDraw.override_colormap)
  567.     curWindowInfo->colormap = new->glxDraw.alt_colormap;
  568.     for (tmpConfig = newConfig; tmpConfig->buffer; tmpConfig++)
  569.     {
  570.     if (tmpConfig->buffer == GLX_NORMAL)
  571.     {
  572.         switch (tmpConfig->mode)
  573.         {
  574.           case GLX_COLORMAP:
  575.         if (!curWindowInfo->colormap)
  576.             curWindowInfo->colormap = (Colormap)tmpConfig->arg;
  577.         break;
  578.           case GLX_VISUAL:
  579.         tmpl.visualid = tmpConfig->arg;
  580.         tmpl.screen   = XScreenNumberOfScreen (XtScreen (new));
  581.         curWindowInfo->visualInfo =
  582.             XGetVisualInfo (XtDisplay(new),
  583.                     VisualScreenMask|VisualIDMask,
  584.                     &tmpl, &nret);
  585.         if (!curWindowInfo->visualInfo)
  586.             error (new,"Couldn't get visual");
  587.         curWindowInfo->depth =
  588.             curWindowInfo->visualInfo->depth;
  589.         break;
  590.         }
  591.     }
  592.     }
  593. }
  594.  
  595. /*------------------------------------------------------------------------
  596.  * Initialize
  597.  *    Called when widget is created (not mapped).  Sets up variables
  598.  *    needed and defaults for the resources.
  599.  *
  600.  * Resources set up:
  601.  *    core.width (100)
  602.  *    core.height (100)
  603.  *    core.colormap
  604.  *    glxDraw.visualInfo
  605.  *    core.depth
  606.  *    glxDraw.isRGB
  607.  *    glxDraw.{overlay_info & underlay_info & popup_info}.
  608.  *        colormap
  609.  *        visualInfo
  610.  *        depth
  611.  *   #ifdef __GLX_MOTIF
  612.  *    primitive.highlight_thickness
  613.  *    primitive.shadow_thickness
  614.  *   #endif
  615.  *
  616.  *        If both buffers are requested:
  617.  *    glxDraw.single_buffer (TRUE if current window is single buffered)
  618.  *    glxDraw.single_buffer_default (TRUE if default window was single)
  619.  *
  620.  *    glxDraw.sgl_buf.config
  621.  *    glxDraw.sgl_buf.info.colormap
  622.  *    glxDraw.sgl_buf.info.visualInfo
  623.  *    glxDraw.sgl_buf.info.depth
  624.  *
  625.  *    glxDraw.dbl_buf.config
  626.  *    glxDraw.dbl_buf.info.colormap
  627.  *    glxDraw.dbl_buf.info.visualInfo
  628.  *    glxDraw.dbl_buf.info.depth
  629.  *
  630.  *    glxDraw.cur_info
  631.  *    glxDraw.alt_colormap
  632.  *
  633.  * Variables set up:
  634.  *    isDouble (TRUE if default window is double buffered)
  635.  *------------------------------------------------------------------------*/
  636.  
  637. static void Initialize (req, new)
  638.   GlxDrawWidget req, new;
  639. {
  640.     GLXconfig        *newConfig;
  641.     GlxDrawWindowInfo    normalWindowInfo;
  642.     GlxDrawWindowInfo    *curWindowInfo;
  643.     XVisualInfo        tmpl;
  644.     register        i;
  645.     int            nret;
  646.     int            isDouble=FALSE;
  647.     
  648. #ifdef DEBUG
  649.     XSynchronize(XtDisplay(new), True);
  650. #endif
  651.     
  652.     /*----
  653.      * Initialize core elements if they aren't already.
  654.      *----*/
  655.  
  656.     if (req->core.width == 0)
  657.     new->core.width = 100;
  658.     if (req->core.height == 0)
  659.     new->core.height = 100;
  660.     
  661.     /*----
  662.      * Initialize the normalWindowInfo structure.  This structure is used
  663.      * to collect all the information about the normal window before it
  664.      * is placed in the widget structure.
  665.      *----*/
  666.  
  667.     bzero (&normalWindowInfo, sizeof (normalWindowInfo));
  668.     normalWindowInfo.exists = TRUE;
  669.  
  670.     /*----
  671.      * By default, we want to override the colormap (we DON'T want to
  672.      * use the core colormap).  If the user has reqeusted that we DO
  673.      * want to use a colormap that he has provided, then do it here.
  674.      *----*/
  675.  
  676.     if (!new->glxDraw.override_colormap)
  677.     normalWindowInfo.colormap = new->core.colormap;
  678.  
  679.     
  680.     /*----
  681.      * Get the configuration information that matches what the user
  682.      * requested.
  683.      *
  684.      * If it fails, just return with an error saying that it isn't
  685.      * supported.
  686.      *----*/
  687.     
  688.     newConfig = GLXgetconfig (XtDisplay(new),
  689.                   XScreenNumberOfScreen(XtScreen(new)),
  690.                   new->glxDraw.config);
  691.     if (!newConfig)
  692.     {
  693.     error(new,"requested visual not supported");
  694.     return;
  695.     }
  696.     
  697.     new->glxDraw.config = newConfig;
  698.  
  699.     /*----
  700.      * Loop through all the entries in the new configuration structure.
  701.      * For each entry:
  702.      *    If there is a colormap entry in the configuration structure,
  703.      *      put it into the appropriate window info structure.
  704.      *    Get the visual info for each of the visuals requested and
  705.      *      provided and place it in the appropriate window info
  706.      *      structure.
  707.      *----*/
  708.     
  709.     new->glxDraw.isRGB = FALSE;    /* Default is not RGB mode */
  710.     for (i=0; newConfig[i].buffer; i++)
  711.     {
  712.     switch (newConfig[i].buffer)
  713.     {
  714.       case GLX_NORMAL:
  715.         curWindowInfo = &normalWindowInfo;
  716.         break;
  717.       case GLX_OVERLAY:
  718.         curWindowInfo = &new->glxDraw.overlay_info;
  719.         break;
  720.       case GLX_UNDERLAY:
  721.         curWindowInfo = &new->glxDraw.underlay_info;
  722.         break;
  723.       case GLX_POPUP:
  724.         curWindowInfo = &new->glxDraw.popup_info;
  725.         break;
  726.     }
  727.     if (!curWindowInfo->exists)
  728.         continue;
  729.     switch (newConfig[i].mode)
  730.     {
  731.       case GLX_DOUBLE:
  732.         if ((newConfig[i].buffer == GLX_NORMAL) &&
  733.         new->glxDraw.provide_Sbuffer)
  734.         isDouble = newConfig[i].arg;
  735.         break;
  736.       case GLX_COLORMAP:
  737.         if (!curWindowInfo->colormap)
  738.         curWindowInfo->colormap = (Colormap)newConfig[i].arg;
  739.         break;
  740.       case GLX_VISUAL:
  741.         tmpl.visualid = newConfig[i].arg;
  742.         tmpl.screen = XScreenNumberOfScreen(XtScreen(new));
  743.         curWindowInfo->visualInfo =
  744.         XGetVisualInfo(XtDisplay(new),VisualScreenMask|VisualIDMask,
  745.                    &tmpl, &nret);
  746.         if (!curWindowInfo->visualInfo)
  747.         error (new,"Couldn't get visual");
  748.         curWindowInfo->depth = curWindowInfo->visualInfo->depth;
  749.         break;
  750.       case GLX_RGB:
  751.         if(newConfig[i].buffer == GLX_NORMAL)
  752.         new->glxDraw.isRGB = newConfig[i].arg;
  753.         break;
  754.     }
  755.     }
  756.     
  757.     new->core.colormap = normalWindowInfo.colormap;
  758.     new->glxDraw.visualInfo = normalWindowInfo.visualInfo;
  759.     new->core.depth = normalWindowInfo.visualInfo->depth;
  760.  
  761. #ifdef DEBUG
  762. #if DEBUG & 0xFFFE
  763.     fprintf (stderr, "GlxDraw: Primary window is %s buffered.\n",
  764.          isDouble ? "double" : "single");
  765. #endif
  766. #if DEBUG & 0x0002
  767.     fprintf (stderr, "GlxDraw: Primary window colormap = 0x%08x\n",
  768.          new->core.colormap);
  769. #endif
  770. #if DEBUG & 0x0008
  771.     fprintf (stderr, "GlxDraw: Primary window visual ID = %d\n",
  772.          new->glxDraw.visualInfo->visualid);
  773.     fprintf (stderr, "         Depth of visual = %d\n",
  774.          new->glxDraw.visualInfo->depth);
  775.     fprintf (stderr, "         Colormap size = %d\n",
  776.          new->glxDraw.visualInfo->colormap_size);
  777. #endif
  778. #endif
  779.     
  780. #ifdef __GLX_MOTIF
  781.     /*----
  782.      * Clear any resources that shouldn't be changed by the user.
  783.      * The following resources cannot be changed by the user
  784.      *----*/
  785.  
  786.     new->primitive.highlight_thickness = 0;
  787.     new->primitive.shadow_thickness = 0;
  788.  
  789. #endif /* __GLX_MOTIF */
  790.  
  791. /*------------------------------------------------------------------------
  792.  * Here we do the work of making another window if the user requested
  793.  * both a double and single buffer capability.
  794.  *------------------------------------------------------------------------*/
  795.  
  796.     if (new->glxDraw.provide_Sbuffer) {
  797.     GLXconfig    d_config[MAX_CONFIG], s_config[MAX_CONFIG];
  798.     GLXconfig    *tmpConfig;
  799.     int        di;
  800.     
  801.         /*----
  802.          * Create config structures that are identical to the one
  803.          * provided by the user except that one is single and the
  804.          * other is double.
  805.          *----*/
  806.  
  807.     di = 0;
  808.     nret = 0;            /* Flag to say if GLX_DOUBLE found */
  809.     for (i = 0; req->glxDraw.config[i].buffer; i++)
  810.     {
  811.         tmpConfig = &req->glxDraw.config[i];
  812.         d_config[di] = *tmpConfig;
  813.         s_config[di] = *tmpConfig;
  814.         if ((tmpConfig->buffer == GLX_NORMAL) &&
  815.         (tmpConfig->mode == GLX_DOUBLE))
  816.         {
  817.         s_config[di].arg = False;
  818.         d_config[di].arg = True;
  819.         nret = 1;
  820.         }
  821.         if (++di >= MAX_CONFIG)
  822.         {
  823.         error ((Widget)req, "GLXconfig to large to duplicate");
  824.         }
  825.     }
  826.     
  827.         /*----
  828.          * User didn't specify buffering in the config so
  829.          * forceably add entry to set GLX_DOUBLE for single and
  830.          * double buffering.  This should never happen.
  831.          *----*/
  832.  
  833.     if (!nret)
  834.     {
  835.         d_config[di].buffer = GLX_NORMAL;
  836.         d_config[di].mode   = GLX_DOUBLE;
  837.         d_config[di].arg    = True;
  838.         s_config[di].buffer    = GLX_NORMAL;
  839.         s_config[di].mode    = GLX_DOUBLE;
  840.         s_config[di].arg    = False;
  841.         di++;
  842.     }
  843.     d_config[di].buffer = s_config[di].buffer = 0;
  844.     
  845.         /*----
  846.          * Setup another window to allow switch to double buffering
  847.          * Depending on which type of window has already been
  848.          * requested, we request the other.
  849.          *----*/
  850.  
  851.     if (!isDouble)        /* Default window was SINGLE BUFFERED */
  852.     {
  853.         new->glxDraw.single_buffer        = TRUE;
  854.         new->glxDraw.single_buffer_default    = TRUE;
  855.  
  856.         /*----
  857.          * Copy currently created window config and info to
  858.          * single buffer structures
  859.          *----*/
  860.  
  861.         new->glxDraw.sgl_buf.config = newConfig;
  862.         memcpy(&new->glxDraw.sgl_buf.info, &normalWindowInfo,
  863.            (size_t)sizeof(normalWindowInfo));
  864.         new->glxDraw.cur_info = &new->glxDraw.sgl_buf.info;
  865.  
  866.         InitializeDup (new, &new->glxDraw.dbl_buf, d_config);
  867.  
  868.         new->glxDraw.alt_colormap = new->glxDraw.dbl_buf.info.colormap;
  869. #ifdef DEBUG
  870. #if DEBUG & 0x0008
  871.         fprintf (stderr, "GlxDraw: Secondary window visual ID = %d\n",
  872.              new->glxDraw.dbl_buf.info.visualInfo->visualid);
  873.         fprintf (stderr, "         Depth of visual = %d\n",
  874.              new->glxDraw.dbl_buf.info.visualInfo->depth);
  875.         fprintf (stderr, "         Colormap size = %d\n",
  876.              new->glxDraw.dbl_buf.info.visualInfo->colormap_size);
  877. #endif
  878. #endif
  879.     }
  880.  
  881.         /*----
  882.          * Setup another window to allow switch to single buffering
  883.          * Default is double buffered
  884.          *----*/
  885.  
  886.     else            /* Default window was DOUBLE BUFFERED */
  887.     {
  888.         new->glxDraw.single_buffer        = FALSE;
  889.         new->glxDraw.single_buffer_default    = FALSE;
  890.         
  891.         /*----
  892.          * Copy default window config and info to double
  893.          * buffer structures
  894.          *----*/
  895.  
  896.         new->glxDraw.dbl_buf.config = newConfig;
  897.         memcpy(&new->glxDraw.dbl_buf.info, &normalWindowInfo,
  898.            (size_t)sizeof(normalWindowInfo));
  899.         new->glxDraw.cur_info = &new->glxDraw.dbl_buf.info;
  900.         
  901.         InitializeDup (new, &new->glxDraw.sgl_buf, s_config);
  902.  
  903.         new->glxDraw.alt_colormap = new->glxDraw.sgl_buf.info.colormap;
  904. #ifdef DEBUG
  905. #if DEBUG & 0x0008
  906.         fprintf (stderr, "GlxDraw: Secondary window visual ID = %d\n",
  907.              new->glxDraw.sgl_buf.info.visualInfo->visualid);
  908.         fprintf (stderr, "         Depth of visual = %d\n",
  909.              new->glxDraw.sgl_buf.info.visualInfo->depth);
  910.         fprintf (stderr, "         Colormap size = %d\n",
  911.              new->glxDraw.sgl_buf.info.visualInfo->colormap_size);
  912. #endif
  913. #endif
  914.     }
  915. #ifdef DEBUG
  916. #if DEBUG & 0x0002
  917.     fprintf (stderr, "GlxDraw: Secondary window colormap = 0x%08x\n",
  918.          new->glxDraw.alt_colormap);
  919. #endif
  920. #endif
  921.     }
  922. }
  923.  
  924. /*------------------------------------------------------------------------
  925.  * SetValuesAux
  926.  *    Set values portion for the auxiliaries
  927.  *------------------------------------------------------------------------*/
  928.  
  929. static void SetValuesAux (w, current, request, new)
  930.   Widget w; /* for obtaining the display */
  931.   GlxDrawWindowInfo *current, *request, *new;
  932. {
  933.     XSetWindowAttributes attributes;
  934.  
  935.     /* Changing the following after create time will harm me */
  936.     new->exists = current->exists;
  937.     new->window = current->window;
  938.     new->depth = current->depth;
  939.     new->visualInfo = current->visualInfo;
  940.  
  941. #ifdef DEBUG
  942. #if DEBUG & 0x0004
  943.     if (new->exists)
  944.     fprintf (stderr, "GlxDraw: Changing values for window 0x%08x\n",
  945.          new->window);
  946. #endif
  947. #if DEBUG & 0x0008
  948.     if (new->exists)
  949.     fprintf (stderr, "GlxDraw: Changing visual for window 0x%08x to %d\n",
  950.          new->window, new->visualInfo->visualid);
  951. #endif
  952. #endif
  953.  
  954.     /* if the colormap has changed, and the window has been
  955.      * created, change the colormap on the window */
  956.     if (current->colormap != new->colormap && new->window)
  957.     {
  958.     attributes.colormap = new->colormap;
  959.     XChangeWindowAttributes(
  960.         XtDisplay(w), new->window, CWColormap, &attributes);
  961. #ifdef DEBUG
  962. #if DEBUG & 0x0002
  963.     if (new->exists)
  964.         fprintf(stderr,
  965.             "GlxDraw: Changing colormap for window 0x%08x to 0x%08x\n",
  966.             new->window, new->colormap);
  967. #endif
  968. #endif
  969.     }
  970. }
  971.  
  972.  
  973. static void ResizeAux();
  974.  
  975. /*------------------------------------------------------------------------
  976.  * SetNewWindow
  977.  *------------------------------------------------------------------------*/
  978.  
  979. static void SetNewWindow(new, newBuffer, oldBuffer)
  980.   GlxDrawWidget        new;
  981.   GlxDrawBuffer        *newBuffer;
  982.   GlxDrawBuffer        *oldBuffer;
  983. {
  984.     Matrix        mSingle;
  985.     Matrix        mProjection;
  986.     Matrix        mViewing;
  987.     Matrix        mTexture;
  988.     long        mode;
  989.  
  990.     Window        root;
  991.     int        x,y;
  992.     unsigned int    width, height, border_width, depth;
  993.  
  994.     long        backFace;
  995.     Boolean        cmMode;
  996.     short        cposX, cposY;
  997.     long        curColor;
  998.     short        cursor;
  999.     unsigned short    usdum;
  1000.     unsigned char    ucdum;
  1001.     long        ldum;
  1002.     Boolean        depthCue;
  1003.     long        drawMode;
  1004.     long        displayMode;
  1005.     long        fontNumber;
  1006.     Coord        curX, curY, curZ, curW;
  1007.     long        gethitcode;
  1008.     Boolean        lineSBackup;
  1009.     long        lineSRepeat;
  1010.     long        lineSReset;
  1011.     long        lineStyle;
  1012.     long        lineWidth;
  1013.     long        colorMap;
  1014.     long        pattern;
  1015.     Screencoord    left,right,top,bottom;
  1016.     long        shadingModel;
  1017.     long        writeMask;
  1018.  
  1019.     new->glxDraw.cur_info       = &newBuffer->info;
  1020.     new->core.window       = newBuffer->info.window; 
  1021.     new->glxDraw.visualInfo    = newBuffer->info.visualInfo;
  1022.     new->glxDraw.overlay_info  = newBuffer->overlay_info;
  1023.     new->glxDraw.underlay_info = newBuffer->underlay_info;
  1024.     new->glxDraw.popup_info    = newBuffer->popup_info;
  1025.  
  1026.  
  1027. /* Get all possible attributes from old window */
  1028.     mode    = getmmode();
  1029.     if(mode == MSINGLE)
  1030.     {
  1031.         mmode(MSINGLE);
  1032.         getmatrix(mSingle);
  1033.     }else{
  1034.         mmode(MPROJECTION);
  1035.         getmatrix(mProjection);
  1036.         mmode(MVIEWING);
  1037.         getmatrix(mViewing);
  1038.         mmode(MTEXTURE);
  1039.         getmatrix(mTexture);
  1040.         mmode(mode);
  1041.     }
  1042.  
  1043.     displayMode    = getdisplaymode();
  1044.  
  1045.     backFace    = getbackface();
  1046.         if(displayMode == DMSINGLE || displayMode == DMDOUBLE)
  1047.     {
  1048.         cmMode        = getcmmode();
  1049.         curColor    = getcolor();
  1050.         colorMap    = getmap();
  1051.     }
  1052.     getcursor (&cursor, &usdum, &usdum, &ldum);
  1053. /*    getcpos (&cposX, &cposY);*/
  1054.     depthCue    = getdcm();
  1055. /*    drawMode     = getdrawmode();*/
  1056.     fontNumber     = getfont();
  1057. /*    getgpos (&curX, &curY, &curZ, &curW);*/
  1058. /*    hitCode        = gethitcode;*/
  1059.     lineSBackup    = getlsbackup();
  1060.     lineSRepeat    = getlsrepeat();
  1061. /*    lineSReset    = getresetls();*/
  1062.     lineStyle    = getlstyle();
  1063. /*    lineWidth    = getlwidth();*/
  1064.     pattern        = getpattern();
  1065.     getscrmask(&left, &right, &bottom, &top);
  1066.     shadingModel    = getsm();
  1067.     writeMask    = getwritemask();
  1068.  
  1069. /* Get geometry of old window, then resize the new one to match */
  1070.     if(!XGetGeometry(XtDisplay (new), oldBuffer->info.window,
  1071.              &root, &x, &y, &width, &height,
  1072.              &border_width, &depth))
  1073.         warning ((Widget)new, "SetNewWindow : XGetGeometry failed");
  1074.  
  1075. /* Map new window for X */
  1076.     XMapRaised (XtDisplay (new), newBuffer->info.window);
  1077.  
  1078. #ifdef DEBUG
  1079. #if DEBUG & 0x0004
  1080.     fprintf (stderr, "GlxDraw: Changing GLX window to 0x%08x\n",
  1081.          newBuffer->info.window);
  1082. #endif
  1083. #endif
  1084.  
  1085. /* Set new window for GL */
  1086.     GLXwinset  (XtDisplay (new), newBuffer->info.window);
  1087.  
  1088.     XResizeWindow(XtDisplay (new), newBuffer->info.window,
  1089.             width, height);
  1090.  
  1091.     viewport(0, (Screencoord) width-1, 0, (Screencoord) height-1);
  1092.  
  1093.     ResizeAux(new,    &newBuffer->overlay_info,
  1094.             &newBuffer->underlay_info,
  1095.             &newBuffer->popup_info);
  1096.  
  1097. /* What kind of display mode am i really in */
  1098.     displayMode    = getdisplaymode();
  1099.  
  1100. /* Set old windows attributes on the new window */
  1101.     if(mode == MSINGLE)
  1102.     { 
  1103.         mmode(MSINGLE);
  1104.         loadmatrix(mSingle);
  1105.     }else{
  1106.             mmode(MPROJECTION);
  1107.             loadmatrix(mProjection);
  1108.             mmode(MVIEWING);
  1109.             loadmatrix(mViewing);
  1110.             mmode(MTEXTURE);
  1111.             loadmatrix(mTexture);
  1112.     }
  1113.     mmode(mode);
  1114.  
  1115.     backface(backFace);
  1116.     setcursor(cursor, usdum, usdum);
  1117.     if(displayMode == DMSINGLE || displayMode == DMDOUBLE)
  1118.     {
  1119.         color(curColor);
  1120.         if(cmMode)
  1121.             onemap();
  1122.         else{
  1123.             multimap();
  1124.             setmap(colorMap);
  1125.         }
  1126.     }
  1127.     depthcue(depthCue);
  1128.     font(fontNumber);
  1129.     lsbackup(lineSBackup);
  1130.     lsrepeat(lineSRepeat);
  1131.     setpattern(pattern);
  1132.     shademodel(shadingModel);
  1133. }
  1134.  
  1135. /*------------------------------------------------------------------------
  1136.  * SetAux        Handle requests to change resources in aux windows.
  1137.  *------------------------------------------------------------------------*/
  1138. static void SetAux (current, request, new)
  1139.   GlxDrawWidget current, request, new; 
  1140. {
  1141.     SetValuesAux(new,
  1142.          ¤t->glxDraw.overlay_info,
  1143.          &request->glxDraw.overlay_info,
  1144.          &new->glxDraw.overlay_info);
  1145.     SetValuesAux(new,
  1146.          ¤t->glxDraw.underlay_info,
  1147.          &request->glxDraw.underlay_info,
  1148.          &new->glxDraw.underlay_info);
  1149.     SetValuesAux(new,
  1150.          ¤t->glxDraw.popup_info,
  1151.          &request->glxDraw.popup_info,
  1152.          &new->glxDraw.popup_info);
  1153. }
  1154.  
  1155.  
  1156. /*------------------------------------------------------------------------
  1157.  * SetValues        Handle requests to change resources.
  1158.  *
  1159.  * Returns:
  1160.  *    True    Xlib must call XClearArea and the <expose> callbacks.
  1161.  *    False    No redrawing is required.
  1162.  *------------------------------------------------------------------------*/
  1163. static Boolean SetValues (current, request, new)
  1164.   GlxDrawWidget current, request, new;
  1165. {
  1166.     SetAux(current, request, new);
  1167.  
  1168. #ifdef __GLX_MOTIF
  1169.     /* The following resources cannot be changed by the user */
  1170.     new->primitive.highlight_thickness = 0;
  1171.     new->primitive.shadow_thickness = 0;
  1172. #endif            /* __GLX_MOTIF */
  1173.  
  1174. /*----
  1175.  * If setting to single buffer mode from double buffer mode.
  1176.  *----*/
  1177.     if (new->glxDraw.single_buffer) {
  1178.         if (!current->glxDraw.single_buffer) {
  1179.       if(current->glxDraw.single_buffer_default)
  1180.             XUnmapWindow(XtDisplay(new), current->glxDraw.dbl_buf.info.window);
  1181.       SetNewWindow(new, &new->glxDraw.sgl_buf, &new->glxDraw.dbl_buf);
  1182.           return(True);    /* Force an expose/redraw */
  1183.         }
  1184.  
  1185. /*----
  1186.  * If setting to double buffer mode from single buffer mode.
  1187.  *----*/
  1188.     } else if (current->glxDraw.single_buffer) {
  1189.       if(!current->glxDraw.single_buffer_default)
  1190.     XUnmapWindow (XtDisplay(new), current->glxDraw.sgl_buf.info.window);
  1191.       SetNewWindow(new, &new->glxDraw.dbl_buf, &new->glxDraw.sgl_buf);
  1192.       return(True);    /* Force an expose/redraw */
  1193.     }
  1194.     return (False);    /* No expose/redraw */
  1195. }
  1196.  
  1197. /*------------------------------------------------------------------------
  1198.  * RealizeAux
  1199.  *    Called to create overlay, underlay and/or popup windows.
  1200.  *
  1201.  * Resources set up:
  1202.  *    glxDraw.overlay_info.window
  1203.  *    glxDraw.underlay_info.window
  1204.  *    glxDraw.popup_info.window
  1205.  *------------------------------------------------------------------------*/
  1206.  
  1207. static void RealizeAux (glw, aux_info, parent)
  1208.   register GlxDrawWidget    glw;
  1209.   register GlxDrawWindowInfo    *aux_info;
  1210.   Window            parent;
  1211. {
  1212.     XSetWindowAttributes aux_attributes;
  1213.     
  1214.     aux_attributes.colormap = aux_info->colormap;
  1215.     aux_attributes.border_pixel = 0;
  1216.     aux_info->window =
  1217.     XCreateWindow(XtDisplay(glw), parent, 0, 0,
  1218.               glw->core.width, glw->core.height, 0,
  1219.               aux_info->depth, InputOutput,
  1220.               aux_info->visualInfo->visual,
  1221.               CWColormap|CWBorderPixel, &aux_attributes);
  1222.     XMapWindow(XtDisplay(glw),aux_info->window);
  1223.     /* We explicitly need the exposure events for this window */
  1224.     XSelectInput(XtDisplay(glw), aux_info->window,    ExposureMask);
  1225.     /* Tell Xt to tell us about the exposure events
  1226.      * Note that this is a private Xt routine that may change in the
  1227.      * future, but it is the only way to get the exposure events.  This
  1228.      * code may need to change in the future
  1229.      */
  1230.     _XtRegisterWindow(aux_info->window,glw);
  1231.  
  1232. #ifdef DEBUG
  1233. #if DEBUG & 0x0004
  1234.     fprintf (stderr, "         Window created = 0x%08x\n", aux_info->window);
  1235. #endif
  1236. #endif
  1237. }
  1238.  
  1239. /*------------------------------------------------------------------------
  1240.  * RealizeDup
  1241.  *    Duplicate of Realize except for secondary window.
  1242.  *------------------------------------------------------------------------*/
  1243.  
  1244. static int RealizeDup(glw, primary, secondary, valueMask, attributes)
  1245.   GlxDrawWidget          glw;
  1246.   GlxDrawBuffer        *primary;
  1247.   GlxDrawBuffer        *secondary;
  1248.   Mask            *valueMask;
  1249.   XSetWindowAttributes    *attributes;
  1250. {
  1251.     GlxDrawWindowInfo    *info;
  1252.     register GLXconfig    *glp;
  1253.     Window        windows[2];
  1254.     int            cmapAlloc;
  1255.     int            has_aux=FALSE;
  1256.     int            i;
  1257.     int            stat;
  1258.  
  1259.     glw->glxDraw.mainWindow = primary->info.window;
  1260.  
  1261.     info = &secondary->info;
  1262.     /*
  1263.      * You must allocate and set a new colormap if the secondary window
  1264.      *    visual doesn't match the primary (Usually the case when
  1265.      *    using this feature, sincde depth in single is greater than double)
  1266.      *
  1267.      * Note the secondary window depth must always be less than the parent
  1268.      *
  1269.      */
  1270.     if(glw->glxDraw.visualInfo->depth != info->depth)
  1271.     {
  1272.     if(glw->glxDraw.visualInfo->depth < info->depth)
  1273.     {
  1274.         error ((Widget)glw,
  1275.            "Fatal error: Child depth greater than parent\n");
  1276.     }
  1277.     }
  1278.     /*
  1279.      * Create an X window for secondary buffer.  Not mapped yet.  It will be
  1280.      * rolled in when appropriate set values is done.
  1281.      */
  1282.     
  1283.     attributes->colormap = info->colormap;
  1284.     *valueMask |= CWColormap;
  1285.     info->window = XCreateWindow (XtDisplay(glw),
  1286.                   XtWindow(glw),
  1287.                   0, 0,
  1288.                   glw->core.width, glw->core.height, 0,
  1289.                   info->depth, InputOutput,
  1290.                   info->visualInfo->visual,
  1291.                   *valueMask, attributes);
  1292.     
  1293. #ifdef ORIGINAL
  1294.     /* this is not needed, and breaks input on 5.1 */
  1295.     XSelectInput (XtDisplay (glw), info->window, ExposureMask);
  1296. #endif
  1297.     _XtRegisterWindow (info->window, glw);
  1298.  
  1299. #ifdef DEBUG
  1300. #if DEBUG & 0x0004
  1301.     fprintf (stderr, "GlxDraw: Secondary window is 0x%08x\n", info->window);
  1302. #endif
  1303. #endif
  1304.  
  1305.     /*
  1306.      * Special case for Indigo Starter which uses a PsuedoColor visual
  1307.      *    for RGB mode.  Requires building my own color map
  1308.      *
  1309.      * Tell window manager I have a special color map
  1310.      */
  1311.     if(glw->glxDraw.isRGB
  1312.        && info->visualInfo->class == PseudoColor)
  1313.     {
  1314.     windows[0] = info->window;
  1315.     stat = XSetWMColormapWindows(XtDisplay(glw),
  1316.                      XtWindow(glw),
  1317.                      windows,
  1318.                      1);
  1319.     if(!stat)
  1320.         warning ((Widget)glw, "XSetWMColormapWindows failed\n");
  1321.     }
  1322.  
  1323.     /*
  1324.      * Copy default auxiliary info to structures for primary and
  1325.      * secondary buffers
  1326.      */
  1327.     primary->overlay_info    = glw->glxDraw.overlay_info;
  1328.     primary->underlay_info    = glw->glxDraw.underlay_info;
  1329.     primary->popup_info    = glw->glxDraw.popup_info;
  1330.     
  1331.     secondary->overlay_info    = glw->glxDraw.overlay_info;
  1332.     secondary->underlay_info= glw->glxDraw.underlay_info;
  1333.     secondary->popup_info    = glw->glxDraw.popup_info;
  1334.     
  1335.     /*
  1336.      * Duplicate auxiliary windows, if necessary, for secondary buffer
  1337.      */
  1338.     if (glw->glxDraw.overlay_info.exists) {
  1339.     has_aux = TRUE;
  1340. #ifdef DEBUG
  1341. #if DEBUG & 0x0004
  1342.     fprintf (stderr, "GlxDraw: Creating secondary overlay window\n");
  1343. #endif
  1344. #endif
  1345.     RealizeAux (glw,&secondary->overlay_info, info->window);
  1346.     }
  1347.     if (glw->glxDraw.underlay_info.exists) {
  1348.     has_aux = TRUE;
  1349. #ifdef DEBUG
  1350. #if DEBUG & 0x0004
  1351.     fprintf (stderr, "GlxDraw: Creating secondary underlay window\n");
  1352. #endif
  1353. #endif
  1354.     RealizeAux (glw,&secondary->underlay_info, info->window);
  1355.     }
  1356.     if (glw->glxDraw.popup_info.exists) {
  1357.     has_aux = TRUE;
  1358. #ifdef DEBUG
  1359. #if DEBUG & 0x0004
  1360.     fprintf (stderr, "GlxDraw: Creating secondary popup window\n");
  1361. #endif
  1362. #endif
  1363.     RealizeAux (glw,&secondary->popup_info, info->window);
  1364.     }
  1365.     
  1366.     /*
  1367.      * Store windows in appropriate places in config structure for GLXlink
  1368.      */
  1369.     for (glp = secondary->config; glp->buffer; glp++) {
  1370.     if (glp->mode == GLX_WINDOW) {
  1371.             switch (glp->buffer) {
  1372.               case GLX_NORMAL:
  1373.                 glp->arg = info->window;
  1374.                 break;
  1375.               case GLX_OVERLAY:
  1376.                 if (secondary->overlay_info.exists)
  1377.                     glp->arg = secondary->overlay_info.window;
  1378.                 break;
  1379.               case GLX_UNDERLAY:
  1380.                 if (secondary->underlay_info.exists)
  1381.                     glp->arg = secondary->underlay_info.window;
  1382.                 break;
  1383.               case GLX_POPUP:
  1384.                 if (secondary->popup_info.exists)
  1385.                     glp->arg = secondary->popup_info.window;
  1386.                 break;
  1387.             }
  1388.     }
  1389.     }
  1390.     
  1391.     
  1392.     
  1393.     /* Link the secondary window for GL */
  1394.     i = GLXlink (XtDisplay (glw), secondary->config);
  1395.     if (i < 0)
  1396.     error (glw, gl_errs[-i]);
  1397.     
  1398.     
  1399.     glw->glxDraw.visualInfo = primary->info.visualInfo;
  1400.     
  1401.     return(has_aux);
  1402. }
  1403.  
  1404. /*------------------------------------------------------------------------
  1405.  * Realize
  1406.  *    Called when widget is to be mapped.  Does final loading of
  1407.  *    resources.  Maps all subwindows (overlay, underlay and popup).
  1408.  *
  1409.  * Resources set up:
  1410.  *    glxDraw.config [GLX_NORMAL & GLX_WINDOW]
  1411.  *    glxDraw.config [GLX_OVERLAY & GLX_WINDOW]
  1412.  *    glxDraw.config [GLX_UNDERLAY & GLX_WINDOW]
  1413.  *    glxDraw.config [GLX_POPUP & GLX_WINDOW]
  1414.  *    glxDraw.mainWindow
  1415.  *    glxDraw.cur_info->window
  1416.  *------------------------------------------------------------------------*/
  1417.  
  1418. static void Realize(w, valueMask, attributes)
  1419.   Widget w;
  1420.   Mask *valueMask;
  1421.   XSetWindowAttributes *attributes;
  1422. {
  1423.     register GlxDrawWidget    glw = (GlxDrawWidget)w;
  1424.     Boolean            has_aux=FALSE;
  1425.     GlxDrawCallbackStruct    cb;
  1426.     register GLXconfig        *glp;
  1427.     XColor            colorDefs[256];
  1428.     int                i;
  1429.  
  1430. /* Since GL programs are expected to clear the screen themselves,
  1431.  * we don't want X to clear the screen, so don't set the background
  1432.  * pixel.
  1433.  */
  1434.     *valueMask &= ~CWBackPixel;
  1435.  
  1436.     XtCreateWindow (w, (unsigned int)InputOutput,
  1437.             glw->glxDraw.visualInfo->visual,
  1438.             *valueMask, attributes);
  1439.  
  1440. #ifdef DEBUG
  1441. #if DEBUG & 0x0004
  1442.     fprintf (stderr, "GlxDraw: Primary window is 0x%08x\n", XtWindow (glw));
  1443. #endif
  1444. #endif
  1445.  
  1446.     if (glw->glxDraw.overlay_info.exists) {
  1447.     has_aux = TRUE;
  1448. #ifdef DEBUG
  1449. #if DEBUG & 0x0004
  1450.     fprintf (stderr, "GlxDraw: Creating primary overlay window\n");
  1451. #endif
  1452. #endif
  1453.     RealizeAux (glw,&glw->glxDraw.overlay_info, XtWindow (glw));
  1454.     }
  1455.     if (glw->glxDraw.underlay_info.exists) {
  1456.     has_aux = TRUE;
  1457. #ifdef DEBUG
  1458. #if DEBUG & 0x0004
  1459.     fprintf (stderr, "GlxDraw: Creating primary underlay window\n");
  1460. #endif
  1461. #endif
  1462.     RealizeAux (glw,&glw->glxDraw.underlay_info, XtWindow (glw));
  1463.     }
  1464.     if (glw->glxDraw.popup_info.exists) {
  1465.     has_aux = TRUE;
  1466. #ifdef DEBUG
  1467. #if DEBUG & 0x0004
  1468.     fprintf (stderr, "GlxDraw: Creating primary popup window\n");
  1469. #endif
  1470. #endif
  1471.     RealizeAux (glw,&glw->glxDraw.popup_info, XtWindow (glw));
  1472.     }
  1473.  
  1474.     /*----
  1475.      * Now go through all the GLXconfig structures and fill
  1476.      * in the GLX_WINDOW argument for each type of window.
  1477.      *----*/
  1478.  
  1479.     for (glp = glw->glxDraw.config; glp->buffer; glp++) {
  1480.     if (glp->mode == GLX_WINDOW) {
  1481.         switch (glp->buffer) {
  1482.           case GLX_NORMAL:
  1483.         glp->arg = XtWindow(glw);
  1484.         glw->glxDraw.mainWindow = XtWindow (glw);
  1485.         break;
  1486.           case GLX_OVERLAY:
  1487.         if (glw->glxDraw.overlay_info.exists)
  1488.             glp->arg = glw->glxDraw.overlay_info.window;
  1489.         break;
  1490.           case GLX_UNDERLAY:
  1491.         if (glw->glxDraw.underlay_info.exists)
  1492.             glp->arg = glw->glxDraw.underlay_info.window;
  1493.         break;
  1494.           case GLX_POPUP:
  1495.         if (glw->glxDraw.popup_info.exists)
  1496.             glp->arg = glw->glxDraw.popup_info.window;
  1497.         break;
  1498.         }
  1499.     }
  1500.     }
  1501.  
  1502.     i = GLXlink(XtDisplay(w), glw->glxDraw.config);
  1503.     if (i < 0)
  1504.     error (glw, gl_errs[-i]);
  1505.  
  1506. /*
  1507.  * If provide_Sbuffer is set then allow switching between single and double
  1508.  * buffering.  Requires creation of a secondary window which is used
  1509.  * for alternate mode.  If main window is double buffered then secondary
  1510.  * window is single buffered and vice versa.
  1511.  *
  1512.  * Underlay, overlay and popups are also duplicated with secondary window
  1513.  * as the parent
  1514.  */
  1515.  
  1516.     if (glw->glxDraw.provide_Sbuffer) {
  1517.     GlxDrawWindowInfo    *curWindowInfo;
  1518.     int            i;
  1519. /*
  1520.  * Set window for the default window in current info structure
  1521.  */
  1522.  
  1523.     glw->glxDraw.cur_info->window = XtWindow (glw);
  1524.  
  1525.  
  1526. /*
  1527.  * Make auxiliary window to allow switch to double buffering 
  1528.  */
  1529.     if(glw->glxDraw.single_buffer_default)
  1530.     {
  1531.         RealizeDup(glw, &glw->glxDraw.sgl_buf.info,
  1532.                 &glw->glxDraw.dbl_buf.info,
  1533.                 valueMask,
  1534.                 attributes);
  1535. /*
  1536.  * or else make auxiliary window to allow switch to single buffering 
  1537.  */
  1538.     }
  1539.     else
  1540.     {
  1541.         RealizeDup(glw, &glw->glxDraw.dbl_buf.info,
  1542.                 &glw->glxDraw.sgl_buf.info,
  1543.                 valueMask,
  1544.                 attributes);
  1545.     }
  1546.     }
  1547.     /* Be a nice guy and do one GLXwinset on the main window.  This avoids
  1548.      * the need to do GLXwinsets in programs with only one window.
  1549.      */
  1550.  
  1551.     GLXwinset(XtDisplay(w), XtWindow(w));
  1552.  
  1553.     if(glw->glxDraw.isRGB)
  1554.     cpack(0);
  1555.     else
  1556.     color(0);
  1557.     clear();
  1558.  
  1559.     /* If there is an overlay or an underlay, we need to be notified if it
  1560.      * is destroyed */
  1561.     if (has_aux)
  1562.     XtAddEventHandler((Widget) glw, SubstructureNotifyMask, FALSE,
  1563.               auxwindow_destroyed, NULL);
  1564.  
  1565.     cb.reason    = GlxCR_GINIT;
  1566.     cb.event    = NULL;
  1567.     cb.window    = XtWindow(glw);
  1568.     cb.width    = glw->core.width;
  1569.     cb.height    = glw->core.height;
  1570.     XtCallCallbackList((Widget) glw, glw->glxDraw.ginit_callback, &cb);
  1571. }
  1572.  
  1573. /*------------------------------------------------------------------------
  1574.  * Redraw
  1575.  *------------------------------------------------------------------------*/
  1576.  
  1577. static void Redraw (glw, event, region)
  1578.   GlxDrawWidget    glw;
  1579.   XEvent    *event;
  1580.   Region    region;
  1581. {
  1582.    GlxDrawCallbackStruct cb;
  1583.    XtCallbackList cblist;
  1584.    
  1585.    cb.reason = GlxCR_EXPOSE;
  1586.    cb.event = event;
  1587.    cb.window = event->xexpose.window;
  1588.    cb.width = glw->core.width;
  1589.    cb.height = glw->core.height;
  1590.    if (cb.window == XtWindow(glw))
  1591.    {
  1592.        cb.buffer = GLX_NORMAL;
  1593.        cblist = glw->glxDraw.expose_callback;
  1594.    }
  1595.    else if (cb.window == glw->glxDraw.dbl_buf.info.window) {
  1596.        cb.buffer = GLX_NORMAL;
  1597.        cblist = glw->glxDraw.expose_callback;
  1598.    }
  1599.    else if (cb.window == glw->glxDraw.sgl_buf.info.window) {
  1600.        cb.buffer = GLX_NORMAL;
  1601.        cblist = glw->glxDraw.expose_callback;
  1602.    }
  1603.    else if (cb.window == glw->glxDraw.overlay_info.window)
  1604.    {
  1605.        cb.buffer = GLX_OVERLAY;
  1606.        cblist = glw->glxDraw.overlay_info.expose_callback;
  1607.    }
  1608.    else if (cb.window == glw->glxDraw.underlay_info.window)
  1609.    {
  1610.        cb.buffer = GLX_UNDERLAY;
  1611.        cblist = glw->glxDraw.underlay_info.expose_callback;
  1612.    }
  1613.    else if (cb.window == glw->glxDraw.popup_info.window)
  1614.    {
  1615.        cb.buffer = GLX_POPUP;
  1616.        cblist = glw->glxDraw.popup_info.expose_callback;
  1617.    }
  1618.    else
  1619.    {
  1620. /*
  1621.  *  Probably a redraw on an inactive secondary window
  1622.  *  Usually from resize, since we have to have resize events to all windows
  1623.  *  but we don't want redraw on inactive windows 
  1624.  */
  1625.     return;
  1626.    }
  1627.    XtCallCallbackList ((Widget) glw, cblist, &cb);
  1628. }
  1629.  
  1630. /*------------------------------------------------------------------------
  1631.  * ResizeCallback
  1632.  *------------------------------------------------------------------------*/
  1633.  
  1634. static void ResizeCallback(glw, window)
  1635.   GlxDrawWidget    glw;
  1636.   Window        window;
  1637. {
  1638.     GlxDrawCallbackStruct cb;
  1639.  
  1640.     cb.reason    = GlxCR_RESIZE;
  1641.     cb.event    = NULL;
  1642.     cb.window    = window;
  1643.     cb.width    = glw->core.width;
  1644.     cb.height    = glw->core.height;
  1645.     cb.buffer    = GLX_NORMAL;
  1646.     /* The following XSync fixes a bug whereby viewport can fail.
  1647.     * On Indigo, viewport queries the size of the X window
  1648.     * and gets the old size without this Xsync.
  1649.     */
  1650.     XSync(XtDisplay(glw),FALSE);
  1651.     XtCallCallbackList ((Widget) glw, glw->glxDraw.resize_callback, &cb);
  1652. }
  1653.  
  1654. /*------------------------------------------------------------------------
  1655.  * ResizeAux
  1656.  *------------------------------------------------------------------------*/
  1657.  
  1658. static void ResizeAux(glw, overlay_info, underlay_info, popup_info)
  1659.   GlxDrawWidget        glw;
  1660.   GlxDrawWindowInfo    *overlay_info, *underlay_info, *popup_info;
  1661. {
  1662.     if (overlay_info->exists && overlay_info->window)
  1663.     XResizeWindow(XtDisplay(glw), overlay_info->window,
  1664.               glw->core.width, glw->core.height);
  1665.     if (underlay_info->exists && underlay_info->window)
  1666.     XResizeWindow(XtDisplay(glw), underlay_info->window,
  1667.               glw->core.width, glw->core.height);
  1668.     if (popup_info->exists && popup_info->window)
  1669.     XResizeWindow(XtDisplay(glw), popup_info->window,
  1670.               glw->core.width, glw->core.height);
  1671. }
  1672.  
  1673. /*------------------------------------------------------------------------
  1674.  * ResizeDup
  1675.  *------------------------------------------------------------------------*/
  1676.  
  1677. static void ResizeDup(glw)
  1678.   GlxDrawWidget glw;
  1679. {
  1680. /*
  1681.  * Resize inactive main, overlay, underlay and popup windows if necessary 
  1682.  */
  1683.     /* Single is current so resize double */
  1684.         if (glw->glxDraw.single_buffer)
  1685.     {
  1686.         XResizeWindow(XtDisplay(glw), glw->glxDraw.dbl_buf.info.window,
  1687.                       glw->core.width, glw->core.height);
  1688.             ResizeAux(glw,    &glw->glxDraw.dbl_buf.overlay_info,
  1689.                 &glw->glxDraw.dbl_buf.underlay_info,
  1690.                 &glw->glxDraw.dbl_buf.popup_info);
  1691.         ResizeCallback(glw, glw->glxDraw.dbl_buf.info.window);
  1692.     /* Double is current so resize single */
  1693.     }else{
  1694.         XResizeWindow(XtDisplay(glw), glw->glxDraw.sgl_buf.info.window,
  1695.                       glw->core.width, glw->core.height);
  1696.             ResizeAux(glw,    &glw->glxDraw.sgl_buf.overlay_info,
  1697.                 &glw->glxDraw.sgl_buf.underlay_info,
  1698.                 &glw->glxDraw.sgl_buf.popup_info);
  1699.         ResizeCallback(glw, glw->glxDraw.sgl_buf.info.window);
  1700.     }
  1701. }
  1702.  
  1703. /*------------------------------------------------------------------------
  1704.  * Resize
  1705.  *------------------------------------------------------------------------*/
  1706.  
  1707. static void Resize(glw)
  1708.   GlxDrawWidget glw;
  1709. {
  1710.  
  1711. /* if we get a resize event before being realized, we can't handle it */
  1712.     if (!XtIsRealized((Widget)glw))
  1713.     return;
  1714.  
  1715. /* Resize current overlay, underlay and popup planes if necessary */
  1716.     ResizeAux(glw, &glw->glxDraw.overlay_info,
  1717.            &glw->glxDraw.underlay_info,
  1718.            &glw->glxDraw.popup_info);
  1719.  
  1720.     if (glw->glxDraw.provide_Sbuffer)
  1721.     {
  1722. /* Resize secondary window */
  1723.     ResizeDup(glw);
  1724.  
  1725. /* Resize callback for current window */
  1726.         ResizeCallback(glw, XtWindow((Widget) glw));
  1727.     }else
  1728.         ResizeCallback(glw, XtWindow((Widget) glw));
  1729. }
  1730.  
  1731. /*------------------------------------------------------------------------
  1732.  * Destroy
  1733.  *------------------------------------------------------------------------*/
  1734.  
  1735. static void Destroy(glw)    
  1736.   GlxDrawWidget glw;
  1737. {
  1738.     XtFree((char *)glw->glxDraw.config);
  1739.     if (glw->glxDraw.overlay_info.exists)
  1740.     {
  1741.     _XtUnregisterWindow(glw->glxDraw.overlay_info.window,glw);
  1742.     glw->glxDraw.overlay_info.exists = FALSE;
  1743.     glw->glxDraw.overlay_info.window = NULL;
  1744.     /*The overlay window will be automatically destroyed when the
  1745.      *widget window is actually destroyed
  1746.      */
  1747.     }
  1748.     if (glw->glxDraw.underlay_info.exists)
  1749.     {
  1750.     _XtUnregisterWindow(glw->glxDraw.underlay_info.window,glw);
  1751.     glw->glxDraw.underlay_info.exists = FALSE;
  1752.     glw->glxDraw.underlay_info.window = NULL;
  1753.     /*The underlay window will be automatically destroyed when the
  1754.      *widget window is actually destroyed
  1755.      */
  1756.     }
  1757.     if (glw->glxDraw.popup_info.exists)
  1758.     {
  1759.     _XtUnregisterWindow(glw->glxDraw.popup_info.window,glw);
  1760.     glw->glxDraw.popup_info.exists = FALSE;
  1761.     glw->glxDraw.popup_info.window = NULL;
  1762.     /*The popup window will be automatically destroyed when the
  1763.      *widget window is actually destroyed
  1764.      */
  1765.     }
  1766.     GLXunlink(XtDisplay((Widget) glw), XtWindow((Widget) glw));
  1767. }
  1768.  
  1769. /*------------------------------------------------------------------------
  1770.  * glxInput
  1771.  *   Action routine for keyboard and mouse events
  1772.  *   ARGSUSED
  1773.  *------------------------------------------------------------------------*/
  1774.  
  1775. static void glxInput (glw, event, params, num_params)
  1776.   GlxDrawWidget glw;
  1777.   XEvent *event;
  1778.   String *params;        /* unused */
  1779.   Cardinal *num_params;        /* unused */
  1780. {
  1781.    GlxDrawCallbackStruct cb;
  1782.    
  1783.    cb.reason = GlxCR_INPUT;
  1784.    cb.event = event;
  1785.    cb.window = XtWindow(glw);
  1786.    cb.buffer = GLX_NORMAL;
  1787.    XtCallCallbackList ((Widget) glw, glw->glxDraw.input_callback, &cb);
  1788. }
  1789.  
  1790. /*------------------------------------------------------------------------
  1791.  * auxwindow_destroyed
  1792.  *   If the user explicitly destroys the overlay or underlay windows,
  1793.  *   clean up
  1794.  *------------------------------------------------------------------------*/
  1795.  
  1796. static void auxwindow_destroyed(glw, client_data, event)
  1797.   GlxDrawWidget glw;
  1798.   caddr_t client_data;
  1799.   XEvent *event;
  1800. {
  1801.     if (event->type == DestroyNotify && event->xdestroywindow.window)
  1802.     {
  1803.     if (glw->glxDraw.overlay_info.exists &&
  1804.         event->xdestroywindow.window == glw->glxDraw.overlay_info.window)
  1805.     {
  1806.         _XtUnregisterWindow(glw->glxDraw.overlay_info.window,glw);
  1807.         glw->glxDraw.overlay_info.exists = FALSE;
  1808.         glw->glxDraw.overlay_info.window = 0;
  1809.     }
  1810.     if (glw->glxDraw.underlay_info.exists &&
  1811.         event->xdestroywindow.window == glw->glxDraw.underlay_info.window)
  1812.     {
  1813.         _XtUnregisterWindow(glw->glxDraw.underlay_info.window,glw);
  1814.         glw->glxDraw.underlay_info.exists = FALSE;
  1815.         glw->glxDraw.underlay_info.window = 0;
  1816.     }
  1817.     if (glw->glxDraw.popup_info.exists &&
  1818.         event->xdestroywindow.window == glw->glxDraw.popup_info.window)
  1819.     {
  1820.         _XtUnregisterWindow(glw->glxDraw.popup_info.window,glw);
  1821.         glw->glxDraw.popup_info.exists = FALSE;
  1822.         glw->glxDraw.popup_info.window = 0;
  1823.     }
  1824.     }
  1825. }
  1826.  
  1827. #ifdef __GLX_MOTIF
  1828.  
  1829. /*------------------------------------------------------------------------
  1830.  * GlxCreateMDraw
  1831.  *   Provide a Motif-style create routine
  1832.  *------------------------------------------------------------------------*/
  1833.  
  1834. Widget GlxCreateMDraw(parent, name, arglist, argcount)
  1835.   Widget parent;
  1836.   char *name;
  1837.   ArgList arglist;
  1838.   Cardinal argcount;
  1839. {
  1840.     return (XtCreateWidget (name, glxMDrawWidgetClass, parent, arglist,
  1841.                 argcount));
  1842. }
  1843. #endif
  1844.  
  1845.